package domain;

import java.sql.Timestamp;
import java.util.List;

import org.eclipse.jdt.internal.compiler.util.Util;

import util.ExpindConstants;
import util.RateUtil;

public class Movie implements Comparable {

	private long mid;
	private User user;
	private String name;
	private String genre;
	private String year;
	private int runTime;
	private String summary;
	private String poster;
	private String linkToMovie;
	private double rating;
	private int popularity;
	private boolean isCompleted;
	private Timestamp timestamp;

	private List<User> directorList;
	private List<Role> actedList;
	private List<User> crewList;
	private List<Role> appliedActorsList;
	private List<CrewJob> crewJobs;
	private List<ActorJob> actorJobs;

	public Movie(long mid, User user, String name, String genre, String year,
			String summary, int runTime, String poster, String linkToMovie,
			double rating, int popularity, boolean isCompleted, /*
																 * List<User>
																 * directorList,
																 * List<User>
																 * actorList,
																 * List<User>
																 * crewList,
																 */
			Timestamp timestamp) {
		this.mid = mid;
		this.user = user;
		this.name = name;
		this.genre = genre;
		this.year = year;
		this.summary = summary;
		this.rating = rating;
		this.popularity = popularity;
		this.poster = poster;
		this.linkToMovie = linkToMovie;
		this.isCompleted = isCompleted;
		/*
		 * this.directorList = directorList; this.actedList = actorList;
		 * this.crewList = crewList;
		 */
		this.timestamp = timestamp;
	}

	public void initializePeopleLists(List<User> directorList,
			List<Role> actorList, List<User> crewList,
			List<Role> appliedActorsList) {
		this.directorList = directorList;
		this.actedList = actorList;
		this.crewList = crewList;
		this.appliedActorsList = appliedActorsList;

	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Timestamp getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Timestamp timestamp) {
		this.timestamp = timestamp;
	}

	public long getMid() {
		return mid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getGenre() {
		return genre;
	}

	public void setGenre(String genre) {
		this.genre = genre;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public int getRunTime() {
		return runTime;
	}

	public void setRunTime(int runTime) {
		this.runTime = runTime;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getPoster() {
		if (poster.startsWith("jsp/")) {
			return ExpindConstants.rootPath + "/" + poster;
		} else
			return poster;
	}

	public void setPoster(String poster) {
		this.poster = poster;
	}

	public String getLinkToMovie() {
		return linkToMovie;
	}

	public void setLinkToMovie(String linkToMovie) {
		this.linkToMovie = linkToMovie;
	}

	public double getRating() {
		return rating;
	}

	public void setRating(double rating) {
		this.rating = rating;
	}

	public int getPopularity() {
		return popularity;
	}

	public void setPopularity(int popularity) {
		this.popularity = popularity;
	}

	public boolean getIsCompleted() {
		return isCompleted;
	}

	public void setIsCompleted(boolean isCompleted) {
		this.isCompleted = isCompleted;
	}

	public List<User> getDirectorList() {
		return this.directorList;
	}

	public void setDirectorList(List<User> directorList) {
		this.directorList = directorList;
	}

	public List<Role> getActorList() {
		return this.actedList;
	}

	public void setActorList(List<Role> actorList) {
		this.actedList = actorList;
	}

	public List<User> getCrewList() {
		return crewList;
	}

	public int getRoundedRate() {
		return RateUtil.getRate(rating);
	}

	public void setCrewList(List<User> crewList) {
		this.crewList = crewList;
	}

	public boolean isCompleted() {
		return this.isCompleted;
	}

	public void setCompleted(boolean isCompleted) {
		this.isCompleted = isCompleted;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this) {
			return true;
		}
		if (obj == null || obj.getClass() != this.getClass()) {
			return false;
		}

		Movie movie = (Movie) obj;
		return mid == movie.getMid();
	}

	@Override
	public int hashCode() {
		return (int) mid;
	}

	@Override
	public int compareTo(Object obj) {
		Movie movie = (Movie) obj;
		return (int) (mid - movie.getMid());
	}

	public List<CrewJob> getCrewJobs() {
		return crewJobs;
	}

	public void setCrewJobs(List<CrewJob> crewJobs) {
		this.crewJobs = crewJobs;
	}

	public List<ActorJob> getActorJobs() {
		return actorJobs;
	}

	public void setActorJobs(List<ActorJob> actorJobs) {
		this.actorJobs = actorJobs;
	}

}